package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.service.ContentCategoryService;
import com.dongdongshop.vo.ContentCategoryVO;
import com.dongdongshop.vo.ContentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("category")
public class ContentCategoryController {

    @Autowired
    private ContentCategoryService ccs;

    //查询全部
    @PostMapping("selectAll")
    public Result selectAll(){
        List<ContentCategoryVO> list = ccs.selectAll();
        return Result.OK().setData(list);
    }

    //增加
    @PostMapping("addCategory")
    public Result addCategory(@RequestBody ContentCategoryVO vo){
        ccs.addCategory(vo);
        return Result.OK();
    }

    //回显
    @PostMapping("toUpdate")
    public Result toUpdate(Long id){
        ContentCategoryVO vo = ccs.toUpdate(id);
        return Result.OK().setData(vo);
    }

    //修改
    @PostMapping("update")
    public Result update(@RequestBody ContentCategoryVO vo){
        ccs.update(vo);
        return Result.OK();
    }

    //删除
    @PostMapping("delete")
    public Result delete(Long[] ids){
        ccs.delete(ids);
        return Result.OK();
    }

}
